package tinybase.basic;

import junit.framework.Assert;

public class BytePointer {
	private byte[] addr;
	
	public BytePointer() {
		addr = null;
	}
	
	public BytePointer(BytePointer bp) {
		this.addr= bp.getArray();
	}

	public BytePointer(byte[] arr) {
		this.addr= arr;
	}
	
	public byte[] getArray() {
		return addr;
	}
	
	public byte[] getArray(int offset) {
		byte[] arr= null;
		System.arraycopy(addr, offset, arr, 0, addr.length);
		return arr;
	}
	
	public void setArray(byte[] addr) {
		this.addr= addr;
	}

	public void copyFromArray(int selfPos, byte[] src, int srcPos, int length) {
		Assert.assertTrue(addr != null);
		Assert.assertTrue(selfPos + length <= addr.length);
		System.arraycopy(src, srcPos, addr, selfPos, length);
	}
	
	public boolean hasArray() {
		return (addr != null);
	}

}
